﻿//-----------------------------------------------------------------------
// <copyright file="IRepository.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: IRepository.cs
// * history : created by qinchaoyue 2017-10-26 10:03:42
// </copyright>
//-----------------------------------------------------------------------

using System.Collections.Generic;
using Slwy.FrameCore.Dependency;

using SqlSugar;

namespace Slwy.Data.Entity.Interfaces
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    /// <typeparam name="TKey">实体key类型 </typeparam>
    public interface IRepository<TEntity, TKey> : IBaseRepository<TEntity>, IScopeDependency
        where TEntity : class, IEntityBase<TKey>, new()
    {
        //void SetConnection(string connectWriteName, string connectReadName, string suffix = "");

        //void SetConnection(string suffix);

        //ISugarQueryable<TEntity> EntitiesChangeTable(string tableName);

        SqlSugarClient Client { get; }

        /// <summary>
        /// 获取 当前单元操作对象
        /// </summary>
        bool TransactionEnabled { get; set; }

        /// <summary>
        /// 实体集合
        /// </summary>
        ISugarQueryable<TEntity> Entities { get; }

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(TEntity entity);

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(IList<TEntity> entities);

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(TEntity[] entities);

        /// <summary>
        /// The insert.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        IInsertable<TEntity> Insert(TEntity entity);

        bool SaveChanges();

        /// <summary>
        /// 根据keyid获取实体
        /// </summary>
        /// <param name="key">keyID</param>
        /// <returns>实体</returns>
        TEntity GetByKey(TKey key);

        /// <summary>
        /// 根据 keyid 更新所有字段
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        IUpdateable<TEntity> Update(TEntity entity);

        /// <summary>
        /// 根据 keyid 更新所有字段
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        IUpdateable<TEntity> Update(IList<TEntity> entities);
    }
}